package cn.helios.org.service.impl;

import cn.helios.basic.utils.PageList;
import cn.helios.org.domain.Department;
import cn.helios.org.mapper.DepartmentMapper;
import cn.helios.org.query.DepartmentQuery;
import cn.helios.org.service.IDepartmentService;
import org.hibernate.validator.internal.util.stereotypes.ThreadSafe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
        // 1.查询分页总条数
        Integer total = departmentMapper.queryCount(departmentQuery);
        // 2.查询当前页数据
        List<Department> rows = departmentMapper.queryData(departmentQuery);

        return new PageList<>(total, rows);
    }
}
